package classes.view
{
	import classes.OX_Application;
	import classes.controller.EClick;
	import classes.view.component.InfoBar;
	
	import org.puremvc.as3.interfaces.IMediator;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;
	
	public class Mediator_Infobar extends Mediator implements IMediator
	{
		public static const NAME:String = "Mediator_Infobar";
		public function Mediator_Infobar(mediatorName:String=null, viewComponent:Object=null)
		{
			super(mediatorName, viewComponent);
			init();
		}
		override public function listNotificationInterests():Array
		{
			return [OX_Application.APPLICATION_EXECUTE,
					OX_Application.THE_FIRST_EXECUTE,
					OX_Application.INCORRECTQUESTION_EXECUTE,
					OX_Application.CLICK_EVENT,
					OX_Application.GAME_START,
					OX_Application.GAME_OVER,
					OX_Application.SINGLE_ROOM_OFF,
					OX_Application.SINGLE_ROOM_START];
		}
		override public function handleNotification(notification:INotification):void
		{
			switch(notification.getName()){
				case OX_Application.APPLICATION_EXECUTE :
					infoBar.infoBarSwitch 			= true;
				break;
				case OX_Application.THE_FIRST_EXECUTE :
					infoBar.infoBarSwitch 			= true;
				break;
				case OX_Application.INCORRECTQUESTION_EXECUTE :
					infoBar.infoBarSwitch 			= true;
					infoBar.infobarUtilSwitch   	= false;
					break;
				case OX_Application.CLICK_EVENT :
					if(String(notification.getBody()) == "single"){
						infoBar.infobarUtilSwitch   = false;
					}
				break;
				case OX_Application.GAME_START : 
					infoBar.infobarUtilSwitch   	= false;
				break;
				case OX_Application.SINGLE_ROOM_OFF :
					infoBar.infobarUtilSwitch		= true;
				break;
				case OX_Application.SINGLE_ROOM_START :
					infoBar.infobarUtilSwitch		= false;
				break;
				case OX_Application.GAME_OVER :
					infoBar.infobarUtilSwitch		= true;
				break;
			}
		}
		
		//initListener.
		private function init():void
		{
			infoBar.addEventListener(EClick.EVENT_CLICK,	onClickInfoUtil);
		}
	
		private function onClickInfoUtil(e:EClick):void
		{
			//trace("util click : " + e._click);
			sendNotification(OX_Application.UTIL_CLICK_EVENT,	e._click);
		}
		
		protected function get infoBar():InfoBar
		{
			return viewComponent as InfoBar;
		}
	}
}